/*--------------------------+
|	   Particle Class		|
|	---------------------	|
|	Manages the data for,	|
|	updates, and renders	|
|	indivudual particles	|
+--------------------------*/

#pragma once

#include <Windows.h>
#include "SGD Wrappers\SGD_Math.h"
#include "SGD Wrappers\CSGD_Direct3D.h"

class Particle {

public:

	// Constructor
	Particle(int image, float lifespan, DWORD color, DWORD endcolor,float startscale, float endscale, tVector2D position, tVector2D direction, float velocity, float rotation, float rotationspeed, D3DBLEND src, D3DBLEND dest);

	// Copy Constructor
	Particle(const Particle& other);

	// Destructor
	~Particle(void);

	// Draws the particle to the screen
	void Render(void) const;

	// Updates the particles data
	void Update(float elapsedTime);

	// Get if the particle should be destroyed
	inline bool IsFinished(void) const { return Destroy; }

	// Change the particle data
	inline void SetImageID(int image)		{ ImageID = image; }
	inline void SetStartColor(DWORD color)	{ StartColor = color; }
	inline void SetEndColor(DWORD color)	{ EndColor = color; }
	inline void SetStartScale(float scale)	{ StartScale = scale; }
	inline void SetEndScale(float scale)	{ EndScale = scale; }
	inline void SetPosition(tVector2D pos)	{ Position = pos; }
	inline void SetDirection(tVector2D dir)	{ Direction = dir; }
	inline void SetVelocity(float vel)		{ Velocity = vel; }
	inline void SetRotation(float rot)		{ Rotation = rot; }
	inline void SetRotationSpeed(float spd) { RotationSpeed = spd; }
	void SetBlendMode(D3DBLEND src, D3DBLEND dest);
	void SetLifetime(float Lifetime);

	// Accessors
	inline int GetImageID(void) { return ImageID; }

	// Add random change to the particle
	void RandomizeScale(float range);
	void RandomizePosition(float xrange, float yrange);
	void RandomizeVelocity(float range);
	void RandomizeRotation(float range);
	void RandomizeRotationSpeed(float range);
	void RandomizeLifetime(float range);

private:

	// Image that the particle displays, if -1, then it is just a pixel
	int ImageID;

	// The particle's lifespan
	float Lifetime;

	// The time after which the particle should be destroyed
	float TimeOfDeath;

	// The color of the particle over time
	DWORD StartColor;
	DWORD CurrentColor;
	DWORD EndColor;

	// The particles scale over time
	float StartScale;
	float CurrentScale;
	float EndScale;

	// The dimensions
	int Width;
	int Height;

	// The particle's current position
	tVector2D Position;

	// The particle's current velocity
	float Velocity;
	tVector2D Direction;

	// The particles facing
	float Rotation;

	// Speed the particle rotates
	float RotationSpeed;

	// Whether or not the particle should be destroyed
	bool Destroy;

	// Individual color files
	BYTE a1;
	BYTE r1;
	BYTE g1;
	BYTE b1;
	BYTE a2;
	BYTE r2;
	BYTE g2;
	BYTE b2;

	// The DirectX Blend modes
	D3DBLEND SourceBlend;
	D3DBLEND DestBlend;
};
